package cn.edu.tju.wallet.repository;

import cn.edu.tju.wallet.domain.Transaction;
import cn.edu.tju.wallet.domain.Transaction.TransactionType;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 交易流水Repository接口
 */
@Repository
public interface TransactionRepository extends JpaRepository<Transaction, Long> {

    /**
     * 根据钱包ID查询交易流水（分页）
     */
    Page<Transaction> findByWalletIdOrderByCreateTimeDesc(Long walletId, Pageable pageable);

    /**
     * 根据钱包ID和交易类型查询交易流水
     */
    Page<Transaction> findByWalletIdAndTypeOrderByCreateTimeDesc(
            Long walletId, TransactionType type, Pageable pageable);

    /**
     * 根据钱包ID和时间范围查询交易流水
     */
    Page<Transaction> findByWalletIdAndCreateTimeBetweenOrderByCreateTimeDesc(
            Long walletId, LocalDateTime startTime, LocalDateTime endTime, Pageable pageable);

    /**
     * 根据订单ID查询交易流水
     */
    List<Transaction> findByOrderId(Long orderId);

    /**
     * 根据关联交易ID查询交易流水
     */
    List<Transaction> findByRelatedTransactionId(Long relatedTransactionId);
}